import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store/index.js'
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  {
    path: '/Aivideo',
    name: 'Aivideo',
    component: () => import('../views/Aivideo/index3.vue'),
  },
  {
    path: '/',
    name: 'isauth',
    component: () => import('../views/isauth.vue'),
  },{
    path: '/',
    name: 'login',
    component: () => import('../views/login.vue'),
  },
  {
    path: '/home',
    name: 'home',
    redirect: {
      name: 'htsy'
    },
    component: () => import('@/views/home.vue'),
    children: [{
        path: '/htsy',
        name: 'htsy',
        redirect: {
          name: 'htsyIndex'
        },
        component: () => import('@/views/htsy/index.vue'),
        children: [{
          path: '/htsy/index',
          name: 'htsyIndex',
          meta: {
            title: '后台首页'
          },
          component: () => import('@/views/htsy/page/htsy.vue'),

        }]
      },
      {
        path: '/wdsp',
        name: 'wdsp',
        redirect: {
          name: 'wdspIndex'
        },
        component: () => import('@/views/wdsp/index.vue'),
        children: [{
            path: '/wdsp/index',
            name: 'wdspIndex',
            meta: {
              title: '我的视频'
            },
            component: () => import('@/views/wdsp/page/wdsp.vue'),
          },
          {
            path: '/wdsp/add',
            name: 'wdspAdd',
            meta: {
              title: '添加视频'
            },
            component: () => import('@/views/wdsp/page/add.vue'),
          },
          {
            path: '/wdsp/tmpl',
            name: 'wdspTmpl',
            meta: {
              title: '视频模板'
            },
            component: () => import('@/views/wdsp/page/tmpl.vue'),
          },
          {
            path: '/wdsp/edit',
            name: 'wdspEdit',
            meta: {
              title: '编辑视频'
            },
            component: () => import('@/views/wdsp/page/edit.vue'),
          },
          {
            path: '/wdsp/automaticrelease',
            name: 'automaticrelease',
            meta: {
              title: '自动发布'
            },
            component: () => import('@/views/wdsp/page/automaticrelease.vue'),
          },
          {
            path: '/wdsp/addautomaticrelease',
            name: 'addautomaticrelease',
            meta: {
              title: '添加任务'
            },
            component: () => import('@/views/wdsp/page/addautomaticrelease.vue'),
          },
          {
            path: '/wdsp/exitautomaticrelease',
            name: 'exitautomaticrelease',
            meta: {
              title: '编辑任务'
            },
            component: () => import('@/views/wdsp/page/exitautomaticrelease.vue'),
          },
        ]
      },
      {
        path: '/wdzh',
        name: 'wdzh',
        meta: {
          title: '我的账号'
        },
        redirect: {
          name: 'wdzhIndex'
        },
        component: () => import('@/views/wdzh/index.vue'),
        children: [{
          path: '/wdzh/index',
          name: 'wdzhIndex',
          meta: {
            title: '我的账号'
          },
          component: () => import('@/views/wdzh/page/wdzh.vue'),
        }]
      },
      {
        path: '/drsc',
        name: 'drsc',
        meta: {
          title: '达人市场'
        },
        component: () => import('../views/drsc/drsc.vue'),
      },
      {
        path: '/tctk',
        name: 'tctk',
        redirect: {
          name: 'tctkIndex'
        },
        component: () => import('@/views/tctk/index.vue'),
        children: [{
            path: '/tctk/index',
            name: 'tctkIndex',
            meta: {
              title: '同城拓客'
            },
            component: () => import('@/views/tctk/page/tctk.vue'),
          },
          {
            path: '/tctk/setting',
            name: 'tctkSetting',
            meta: {
              title: '账号设置'
            },
            component: () => import('@/views/tctk/page/setting.vue'),
          },
          {
            path: '/tctk/add',
            name: 'tctkAdd',
            meta: {
              title: '添加账号'
            },
            component: () => import('@/views/tctk/page/add.vue'),
          },
          {
            path: '/tctk/tmpl',
            name: 'tctkTmpl',
            meta: {
              title: '视频模板'
            },
            component: () => import('@/views/tctk/page/tmpl.vue'),
          },
          {
            path: '/tctk/edit',
            name: 'tctkEdit',
            meta: {
              title: '编辑视频'
            },
            component: () => import('@/views/tctk/page/edit.vue'),
          },
          {
            path: '/tctk/xs',
            name: 'tctkXs',
            meta: {
              title: '拓客数'
            },
            component: () => import('@/views/tctk/page/xs.vue'),
          },
        ]
      },
      {
        path: '/jzhk',
        name: 'jzhk',
        redirect: {
          name: 'jzhkIndex'
        },
        component: () => import('@/views/jzhk/index.vue'),
        children: [{
            path: '/jzhk/index',
            name: 'jzhkIndex',
            meta: {
              title: '精准获客'
            },
            component: () => import('@/views/jzhk/page/jzhk.vue'),
          },
          {
            path: '/jzhk/xs',
            name: 'jzhkXs',
            meta: {
              title: '精准获客线索'
            },
            component: () => import('@/views/jzhk/page/xs.vue'),
          }
        ]
      },
      {
        path: '/hydr',
        name: 'hydr',
        meta: {
          title: '行业达人'
        },
        redirect: {
          name: 'hydrIndex'
        },
        component: () => import('@/views/hydr/index.vue'),
        children: [{
            path: '/hydr/index',
            name: 'hydrIndex',
            meta: {
              title: '行业达人'
            },
            component: () => import('@/views/hydr/page/hydr.vue'),
          },
          {
            path: '/hydr/xs',
            name: 'hydrXs',
            meta: {
              title: '行业达人线索'
            },
            component: () => import('@/views/hydr/page/xs.vue'),
          }
        ]
      },
      {
        path: '/xpxs',
        name: 'xpxs',
        meta: {
          title: '询盘线索'
        },
        component: () => import('../views/xpxs/xpxs.vue'),
      },
      {
        path: '/dyrb',
        name: 'dyrb',
        meta: {
          title: '抖音热榜'
        },
        component: () => import('../views/dyrb/dyrb.vue'),
      },
      {
        path: '/tkfs',
        name: 'tkfs',
        meta: {
          title: '拓客粉丝'
        },
        component: () => import('../views/tkfs/tkfs.vue'),
      },
    ]
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: '/adminv7/',
  routes
})
// 前置路由守卫
router.beforeEach((to, from, next) => {
  let history = store.state.history
  let result = history.find((v) => v.name == to.name);
  if (!result && to.name != 'login') {
    store.commit("addHistory", to);
  }
  console.log(history, "history")
  // 想要进入购物车页面，必须有token
  console.log('to:', to)
  // if (to.name == 'login') {
  //   next()
  // } else {
  //   let user = window.sessionStorage.getItem('person')
  //   if (user) {
  //     next()
  //   } else {
  //     router.push({ name: 'login' })
  //   }
  // }
  next()
})
export default router
